import numpy as np
from python_ai.common.xcommon import *

frame_len = 400
frame_stride = 160
n_frames = 196

sep('By np.tile')
idx_col = np.tile(np.arange(0, frame_len), (n_frames, 1))
print(idx_col)
print_numpy_ndarray_info(idx_col, 'idx_col')
idx_row = np.tile(np.arange(0, n_frames * frame_stride, frame_stride).reshape(-1, 1), (1, frame_len))
print(idx_row)
print_numpy_ndarray_info(idx_row, 'idx_row')
idx = np.int64(idx_col + idx_row)
print(idx)
print_numpy_ndarray_info(idx, 'idx')

sep('By broadcasting')
idx_col = np.arange(0, frame_len).reshape(1, -1)
print(idx_col)
print_numpy_ndarray_info(idx_col, 'idx_col')
idx_row = np.arange(0, n_frames * frame_stride, frame_stride).reshape(-1, 1)
print(idx_row)
print_numpy_ndarray_info(idx_row, 'idx_row')
idx_broadcast = np.int64(idx_col + idx_row)
print(idx_broadcast)
print_numpy_ndarray_info(idx_broadcast, 'idx_broadcast')

sep('Compare')
print(np.allclose(idx, idx_broadcast))
print(np.isclose(idx, idx_broadcast))
print(np.unique(np.isclose(idx, idx_broadcast)))
